/** @odoo-module **/
import { Dialog } from "@web/core/dialog/dialog";
import {EventBus, Component, onWillStart,onMounted,onWillDestroy, mount, xml, useEnv, App, reactive, useState,useRef } from "@odoo/owl";
import { rpc } from "@web/core/network/rpc";
import { DateTimeField } from "@web/views/fields/datetime/datetime_field";
import { useService ,useOwnedDialogs} from "@web/core/utils/hooks";
 
export class websocketshili extends Component {
   
    static template = "websoketmoban";
 
setup() {
    this.busService = useService("bus_service");  
    this.state = useState({  
        displayText: "",  
        isTyping: false  
    });  
    onWillStart(() => {  
        this.addBusListener();  
    });  
    onWillDestroy(() => {  
        this.removeBusListener();  
    });  
    onMounted(() => {
     
 
       

  

    });
    
}
addBusListener() {  
    this.busService.addChannel("channel001");  
    this.busService.subscribe('typing_message', this.onTypingMessage.bind(this));  


}  
  
removeBusListener() {  
    this.busService.removeEventListener('typing_message', this.onTypingMessage.bind(this));  
}  
  
onTypingMessage(payload) {  
    console.log('Received message:', payload); // 调试用  
    this.state.displayText = this.state.displayText+ payload.text || '';  
    this.state.isTyping = !payload.is_complete;  
}  
async fasong(){
    //f'channel001',  
   // 'typing_message',  

    const results = await fetch ("/my_module/websoket");
    console.log(results);
}

}
websocketshili.components = {
  Dialog
  };
  websocketshili.props =  {"*":true} 
